//
//  DetailMakeSureViewController.m
//  PYWGetColor
//
//  Created by 杜文杰 on 2018/6/18.
//  Copyright © 2018年 dwj. All rights reserved.
//

#import "DetailMakeSureViewController.h"

#import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件
#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
#import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
#import <BaiduMapAPI_Cloud/BMKCloudSearchComponent.h>//引入云检索功能所有的头文件
#import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>//引入计算工具所有的头文件
#import <BaiduMapAPI_Radar/BMKRadarComponent.h>//引入周边雷达功能所有的头文件
#import <BaiduMapAPI_Map/BMKMapView.h>//只引入所需的单个头文件
#import <CoreLocation/CoreLocation.h>

#import "StarView.h"
#import "DetailMakeSureTableViewCell.h"
#import "BrowPhotoView.h"
#import "DetalMakeSureModel.h"
#import "WJChatViewController.h"

@interface DetailMakeSureViewController ()<UITableViewDelegate,UITableViewDataSource,BMKMapViewDelegate, BMKPoiSearchDelegate,CLLocationManagerDelegate>
{
    BMKMapView *_mapView;
    BMKPoiSearch *_searcher;
    BMKGeoCodeSearch *geoCodeSearch;
}
@property (nonatomic, strong) UITableView *mainTableView; // 主框架
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIView *footerView;
@property (nonatomic, strong) NSMutableArray *testArray; // 测试数据源
@property (nonatomic, strong) DetalMakeSureModel *detalMakeSureModel; //
@property (nonatomic, strong) NSMutableArray *datamuArray; // 评论的数据源
@property (nonatomic, strong) UILabel *commentAndPriceLabel; // 评论数 和 价格
@property (nonatomic, strong) UILabel *typeNmaeLabel; // 顶部标题
@property (nonatomic, strong) UILabel *titleNmaeLabel;// 服务标题
@property (nonatomic, strong) UILabel *orderDistanceLabel; // 服务简介
@property (nonatomic, strong) UILabel *customerAddressLabel; // 用户点评
@property (nonatomic, strong) StarView *starView; // 小星星
@property (nonatomic, strong) UIButton *doLikeBtn; // 喜欢
@property (nonatomic, strong) UILabel *label; // 地址
@property (nonatomic, strong) UIImageView *middleImg; // 中间图片
@property (nonatomic, strong) UIButton *makeSureBtn; // 等待确认
@property (nonatomic, assign) BOOL isLike; // 1收藏 0未收藏
@property (nonatomic, strong) UIImageView *vadioImageView; // 模糊图片
@property (nonatomic, strong) UIVisualEffectView *effectView;// 毛玻璃处理模糊图片
@end

@implementation DetailMakeSureViewController
/**
 请求界面总体数据
 参数名    必选    类型    说明
 siteid    是    int    搜索结果中服务者的id
 */
- (void)detailInfoMationDataList {
    NSString *siteid = [self.typeStrXq isEqualToString:@"2"]?self.serverModellList.siteid : self.mineOrderModelList.siteid;
    NSDictionary *parameter = @{@"siteid":siteid,@"uid":[UserModel sharedInstanced].userId};
    
    [[AFAppDotNetAPIClient sharedClient] POST:@"interface.php?m=serverinfo" parameters:parameter progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"error_code"] isEqualToString:@"0"]) {
            self.detalMakeSureModel = [DetalMakeSureModel yy_modelWithDictionary:responseObject[@"data"]];
            [self.datamuArray addObjectsFromArray:self.detalMakeSureModel.commentlist];
            
            self.typeNmaeLabel.text = [NSString stringWithFormat:@"   %@",self.detalMakeSureModel.toptitle];
            self.titleNmaeLabel.text = self.detalMakeSureModel.sitetitle;
            self.orderDistanceLabel.text = self.detalMakeSureModel.sitedesc;
            int startNumInt = [self.detalMakeSureModel.starnum intValue];
            [_starView showMarkWithStar:startNumInt];
            self.commentAndPriceLabel.text = [NSString stringWithFormat:@"(%@) . 价格 ￥%@",self.detalMakeSureModel.commentnum,self.detalMakeSureModel.price];
            // 设置收藏图片
            if ([self.detalMakeSureModel.is_collect isEqualToString:@"1"]) {
                [self.doLikeBtn setImage:[UIImage imageNamed:@"btn_aldolike"] forState:UIControlStateNormal];
                self.isLike = YES;
            }else{
                [self.doLikeBtn setImage:[UIImage imageNamed:@"btn_wjdolike"] forState:UIControlStateNormal];
                self.isLike = NO;
            }
            //按钮状态
            if ([self.detalMakeSureModel.response isEqualToString:@"0"]) {
                [self.makeSureBtn setTitle:@"确认预约" forState:UIControlStateNormal];
            }
            if ([self.detalMakeSureModel.response isEqualToString:@"1"]) {
                [self.makeSureBtn setTitle:@"等待确认" forState:UIControlStateNormal];
            }
            if ([self.detalMakeSureModel.response isEqualToString:@"2"]) {
                [self.makeSureBtn setTitle:@"进行中" forState:UIControlStateNormal];
            }
            if ([self.detalMakeSureModel.response isEqualToString:@"3"]) {
                [self.makeSureBtn setTitle:@"待支付" forState:UIControlStateNormal];
            }
            // 地图添加大头针位置
            BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
            CLLocationCoordinate2D coor;
            coor.latitude = [self.detalMakeSureModel.lat doubleValue];
            coor.longitude = [self.detalMakeSureModel.lnt doubleValue];
            annotation.coordinate = coor;
            [_mapView   addAnnotation:annotation];
            // 设置地图 中心点
            BMKCoordinateRegion region;
            region.center.latitude = [self.detalMakeSureModel.lat doubleValue];
            region.center.longitude = [self.detalMakeSureModel.lnt doubleValue];
            _mapView.region = region;
            
            NSString *str = [NSString stringWithFormat:@"地址\n%@",self.detalMakeSureModel.address];
//            NSString *str = @"地址\n北京市昌平区传智播客";
            NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str];
            [attrStr addAttribute:NSFontAttributeName
                            value:DEF_FontSize_14
                            range:NSMakeRange(0, 2)];
            NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
            //行间距
            paragraph.lineSpacing = 0;
            //段落间距
            paragraph.paragraphSpacing = 0;
            //对齐方式
            paragraph.alignment = NSTextAlignmentLeft;
            //指定段落开始的缩进像素
            paragraph.firstLineHeadIndent = 0;
            //调整全部文字的缩进像素
            paragraph.headIndent = 0;
            //        attrStr添加段落设置
            [attrStr addAttribute:NSParagraphStyleAttributeName
                            value:paragraph
                            range:NSMakeRange(0, 2)];
            //设置label的富文本
            self.label.attributedText = attrStr;
            
            [self.middleImg sd_setImageWithURL:[NSURL URLWithString:self.detalMakeSureModel.slideimg]];
            [self.vadioImageView sd_setImageWithURL:[NSURL URLWithString:self.detalMakeSureModel.slideimg]];
            [self.mainTableView reloadData];
        }else{
            ShowMessage(@"操作失败");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self showError:error];
    }];
}
/**
 uid    是    int    用户id
 siteid    是    int    所预约的工人的id
 lat    是    int    用户定位纬度
 lnt    是    int    用户定位经度
 address    是    int    用户定位详细地址
 */
- (void)makeSureYuYue {
    [self.datamuArray removeAllObjects];
    [[AFAppDotNetAPIClient sharedClient] POST:@"interface.php?m=book" parameters:@{@"uid":[UserModel sharedInstanced].userId,@"siteid":self.serverModellList.siteid,@"lat":[UserModel sharedInstanced].latitude,@"lnt":[UserModel sharedInstanced].longitude,@"address":[UserModel sharedInstanced].locationAddress} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"error_code"] isEqualToString:@"0"]) {
//            ShowMessage(@"操作成功");
            [self.makeSureBtn setTitle:@"等待确认" forState:UIControlStateNormal];
        }else{
            ShowMessage(@"操作失败");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self showError:error];
    }];
}
/**
 取消收藏
 uid    是    string    用户id
 service_id    是    string    服务id
 */
- (void)collectDelete {
    [self.datamuArray removeAllObjects];
    [[AFAppDotNetAPIClient sharedClient] POST:@"interface.php?m=collectDelete" parameters:@{@"uid":[UserModel sharedInstanced].userId,@"service_id":self.serverModellList.siteid} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"error_code"] isEqualToString:@"0"]) {
            ShowMessage(@"操作成功");
            [self.doLikeBtn setImage:[UIImage imageNamed:@"btn_wjdolike"] forState:UIControlStateNormal];
            self.isLike = NO;
        }else{
            ShowMessage(@"操作失败");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self showError:error];
    }];
}
/**
 收藏
 uid    是    string    用户id
 service_id    是    string    服务id
 */
- (void)collectInfoMation {
    [self.datamuArray removeAllObjects];
    [[AFAppDotNetAPIClient sharedClient] POST:@"interface.php?m=collect" parameters:@{@"uid":[UserModel sharedInstanced].userId,@"service_id":self.serverModellList.siteid} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"error_code"] isEqualToString:@"0"]) {
            ShowMessage(@"操作成功");
            [self.doLikeBtn setImage:[UIImage imageNamed:@"btn_aldolike"] forState:UIControlStateNormal];
            self.isLike = YES;
        }else{
            ShowMessage(@"操作失败");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self showError:error];
    }];
}

- (void)telephoneBtnAction:(UIButton *)btn
{
    NSLog(@"呼叫");
    [self callPhone:self.detalMakeSureModel.mobile];
}
- (void)talkaboutBtnAction:(UIButton *)btn
{
    NSLog(@"微聊");
    NSString *telephoneStr = [UserModel sharedInstanced].mobile;
    EMError *error2 = [[EMClient sharedClient] loginWithUsername:telephoneStr password:telephoneStr];
    if (!error2) {
        NSLog(@"登录成功");
        [[EMClient sharedClient].options setIsAutoLogin:YES];// 自动登录
    }
    //环信ID:@"8001"
    //聊天类型:EMConversationTypeChat
    WJChatViewController *chatController = [[WJChatViewController alloc] initWithConversationChatter:self.detalMakeSureModel.mobile conversationType:EMConversationTypeChat];
    [self.navigationController pushViewController:chatController animated:YES];
    
}
- (void) makeSureBtnAction:(UIButton *)btn
{
    NSLog(@"确认预约");
    if ([self.makeSureBtn.titleLabel.text isEqualToString:@"确认预约"]) {
        [self makeSureYuYue];
    }else{
        ShowMessage(@"等待接单中");
    }
}
- (void) doLikeBtnAction:(UIButton *)btn
{
    NSLog(@"收藏");
    if (self.isLike) { // 收藏状态  调取消收藏接口
        [self collectDelete];
    }else{ // 未收藏状态  调收藏接口
        [self collectInfoMation];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"详细信息";
    
    self.navigationController.navigationBar.hidden = NO;
    [self detailInfoMationDataList];
    UIImageView *bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    bgImageView.image = [UIImage imageNamed:@"bg"];
    [self.view addSubview:bgImageView];
    [self.view addSubview:self.mainTableView];
}
#pragma mark - 自定义返回按钮
- (void)addBackButton {
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 64)];
    [backButton addTarget:self action:@selector(onBack) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:@"nav_btn_fh"] forState:UIControlStateNormal];
//    [backButton setTitle:@"返回" forState:UIControlStateNormal];
    [backButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
    backButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 54);
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
}

- (void)onBack {
    [self dismissViewControllerAnimated:NO completion:nil];
}
- (void)viewDidAppear:(BOOL)animated
{
    [self addBackButton];
}
#pragma mark -UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datamuArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailMakeSureTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailMakeSureTableViewCell class])];
//    cell.models = self.testArray[indexPath.row];
    cell.models = self.datamuArray[indexPath.row];
    cell.imagesblock = ^(NSArray * photoUrlsArray, NSInteger startIndex, NSArray * views) {
        [self showImageWithPhotoURLsArray:photoUrlsArray startIndex:startIndex fromViews:views];
    };
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}
#pragma mark - init
- (UITableView *)mainTableView
{
    if (!_mainTableView) {
        _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(10 / WIDTH_6S_SCALE, 20 / HEIGHT_6S_SCALE, SCREEN_WIDTH - 20 / WIDTH_6S_SCALE, SCREEN_HEIGHT - SafeAreaBottomHeight - SafeAreaTopHeight - 20 / HEIGHT_6S_SCALE) style:UITableViewStyleGrouped];
        _mainTableView.backgroundColor = getColor(@"CEC9D5");
        _mainTableView.tableHeaderView = self.headerView;
        _mainTableView.tableFooterView = self.footerView;
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        _mainTableView.showsVerticalScrollIndicator = NO;
        _mainTableView.showsHorizontalScrollIndicator = NO;
        _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        // 动态行高
        _mainTableView.rowHeight = UITableViewAutomaticDimension;
        // 预估行高
        _mainTableView.estimatedRowHeight = 80;
        [_mainTableView registerClass:[DetailMakeSureTableViewCell class] forCellReuseIdentifier:NSStringFromClass([DetailMakeSureTableViewCell class])];
        _mainTableView.layer.cornerRadius = 10;
        _mainTableView.layer.masksToBounds = YES;
    }
    return _mainTableView;
}
- (UIView *)headerView
{
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 660 / HEIGHT_6S_SCALE)];
        _headerView.backgroundColor = [UIColor clearColor];
        
        UILabel *typeNmaeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, _headerView.frame.size.width, 35 / HEIGHT_6S_SCALE)];
        typeNmaeLabel.backgroundColor = getColor(@"B4B0C0");
        typeNmaeLabel.textColor = getColor(blackColor);
        typeNmaeLabel.font = DEF_FontSize_14;
        typeNmaeLabel.textAlignment = NSTextAlignmentLeft;
//        typeNmaeLabel.text = @"   下水道维修工人(20个)";
        self.typeNmaeLabel = typeNmaeLabel;
        [_headerView addSubview:typeNmaeLabel];
        
        UILabel *titleNmaeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(typeNmaeLabel.frame),SCREEN_WIDTH , 45 / HEIGHT_6S_SCALE)];
        titleNmaeLabel.backgroundColor = [UIColor clearColor];
        titleNmaeLabel.textColor = [UIColor blackColor];
        titleNmaeLabel.font = DEF_FontSize_16;
        titleNmaeLabel.textAlignment = NSTextAlignmentCenter;
//        titleNmaeLabel.text = @"黄师傅(浑南长白舒家屯)";
        self.titleNmaeLabel = titleNmaeLabel;
        [_headerView addSubview:titleNmaeLabel];
        
        UIView *lineView1 = [[UIView alloc]init];
        lineView1.backgroundColor = getColor(@"B4B0C0");
        [_headerView addSubview:lineView1];
        [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.top.equalTo(titleNmaeLabel.mas_bottom);
            make.height.mas_equalTo(0.5);
        }];
        // 服务简介
        _orderDistanceLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _orderDistanceLabel.backgroundColor = [UIColor clearColor];
        _orderDistanceLabel.textColor = getColor(blackColor);
        _orderDistanceLabel.textAlignment = NSTextAlignmentLeft;
        _orderDistanceLabel.numberOfLines = 0;
        _orderDistanceLabel.font = DEF_FontSize_14;
        [_orderDistanceLabel sizeToFit];
//        _orderDistanceLabel.text = @"维修站点 . 500米";
        [_headerView addSubview:_orderDistanceLabel];
        
        [self.orderDistanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView1.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(200 / WIDTH_6S_SCALE);
        }];
        
        _customerAddressLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _customerAddressLabel.backgroundColor = [UIColor clearColor];
        _customerAddressLabel.textColor = getColor(textColor);
        _customerAddressLabel.textAlignment = NSTextAlignmentLeft;
        _customerAddressLabel.numberOfLines = 0;
        _customerAddressLabel.font = DEF_FontSize_14;
        [_customerAddressLabel sizeToFit];
        _customerAddressLabel.text = @"用户点评 ";
        __weak typeof(self)weakself = self;
        [_headerView addSubview:_customerAddressLabel];
        [self.customerAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.orderDistanceLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(weakself.orderDistanceLabel);
        }];
        
        _starView = [[StarView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.customerAddressLabel.frame) + 10, CGRectGetMaxY(self.orderDistanceLabel.frame) + 10, 60, 15)];
        [_starView showMarkWithStar:4];
        [_headerView addSubview:_starView];
        [self.starView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakself.customerAddressLabel.mas_centerY);
            make.left.equalTo(weakself.customerAddressLabel.mas_right).offset(2 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(15 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(60 / WIDTH_6S_SCALE);
        }];
        
        _commentAndPriceLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _commentAndPriceLabel.backgroundColor = [UIColor clearColor];
        _commentAndPriceLabel.textColor = getColor(textColor);
        _commentAndPriceLabel.textAlignment = NSTextAlignmentLeft;
        _commentAndPriceLabel.numberOfLines = 0;
        _commentAndPriceLabel.font = DEF_FontSize_14;
        [_commentAndPriceLabel sizeToFit];
        _commentAndPriceLabel.text = @"(674) . 价格￥50 ";
        [_headerView addSubview:_commentAndPriceLabel];
        [self.commentAndPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakself.starView.mas_centerY);
            make.left.equalTo(weakself.starView.mas_right).offset(10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(120 / WIDTH_6S_SCALE);
        }];
        
        UIButton *doLikeBtn = [[UIButton alloc]init];
//        [doLikeBtn setBackgroundColor:getColor(mainColor)];
        [doLikeBtn setTitleColor:getColor(whiteColor) forState:UIControlStateNormal];
        [doLikeBtn setImage:[UIImage imageNamed:@"btn_wjdolike"] forState:UIControlStateNormal];
        [doLikeBtn addTarget:self action:@selector(doLikeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        self.doLikeBtn = doLikeBtn;
        [_headerView addSubview:doLikeBtn];
        [self.doLikeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakself.commentAndPriceLabel.mas_centerY);
            make.left.equalTo(weakself.commentAndPriceLabel.mas_right).offset(10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(22 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(26 / WIDTH_6S_SCALE);
        }];
        
        //1. 初始化地图
        _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.customerAddressLabel.frame) + 10 / HEIGHT_6S_SCALE, _headerView.bounds.size.width, 150 / HEIGHT_6S_SCALE)];
        [_headerView addSubview:_mapView];
        [_mapView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.customerAddressLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(150 / HEIGHT_6S_SCALE);
        }];
        
        //2. 设置地图类型
        //切换为卫星图
        [_mapView setMapType:BMKMapTypeStandard];
        
//        BMKCoordinateRegion region;
//        region.center.latitude = 41.80000;
//        region.center.longitude = 123.38333;
//        _mapView.region = region;
        
        _mapView.zoomLevel = 16;
        //3. 交通图
        //打开实时路况图层
//        [_mapView setTrafficEnabled:YES];
        //    [self getJingWeiDu];// 定位
        
        _mapView.layer.cornerRadius = 10;
        _mapView.layer.masksToBounds = YES;
        
        UIView *lineView2 = [[UIView alloc]init];
        lineView2.backgroundColor = getColor(@"B4B0C0");
        [_headerView addSubview:lineView2];
        [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.top.equalTo(_mapView.mas_bottom).offset(15 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(0.5);
        }];
        
        UIButton *telephoneBtn = [[UIButton alloc]init];
        [telephoneBtn setBackgroundColor:getColor(@"E2E1E5")];
        [telephoneBtn setTitleColor:getColor(mainColor) forState:UIControlStateNormal];
        [telephoneBtn setImage:[UIImage imageNamed:@"list_call"] forState:UIControlStateNormal];
        [telephoneBtn setTitle:@"呼叫" forState:UIControlStateNormal];
        telephoneBtn.titleLabel.font = DEF_FontSize_14;
        telephoneBtn.layer.cornerRadius = 5;
        telephoneBtn.layer.masksToBounds = YES;
        telephoneBtn.imageEdgeInsets = UIEdgeInsetsMake(-15, 20, 0, 0);
        telephoneBtn.titleEdgeInsets = UIEdgeInsetsMake(15, -20, 0, 0);
        [telephoneBtn addTarget:self action:@selector(telephoneBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [_headerView addSubview:telephoneBtn];
        [telephoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_mapView);
            make.top.equalTo(lineView2.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo((SCREEN_WIDTH - 10 / WIDTH_6S_SCALE * 3 - 10 / WIDTH_6S_SCALE * 2) * 0.5);
            make.height.mas_equalTo(42 / HEIGHT_6S_SCALE);
        }];
        UIButton *talkaboutBtn = [[UIButton alloc]init];
        [talkaboutBtn setBackgroundColor:getColor(@"E2E1E5")];
        [talkaboutBtn setTitleColor:getColor(mainColor) forState:UIControlStateNormal];
        [talkaboutBtn setImage:[UIImage imageNamed:@"list_im"] forState:UIControlStateNormal];
        [talkaboutBtn setTitle:@"微聊" forState:UIControlStateNormal];
        talkaboutBtn.titleLabel.font = DEF_FontSize_14;
        talkaboutBtn.layer.cornerRadius = 5;
        talkaboutBtn.layer.masksToBounds = YES;
        talkaboutBtn.imageEdgeInsets = UIEdgeInsetsMake(-15, 20, 0, 0);
        talkaboutBtn.titleEdgeInsets = UIEdgeInsetsMake(15, -20, 0, 0);
        [talkaboutBtn addTarget:self action:@selector(talkaboutBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [_headerView addSubview:talkaboutBtn];
        [talkaboutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_mapView);
            make.centerY.equalTo(telephoneBtn.mas_centerY);
            make.width.mas_equalTo((SCREEN_WIDTH - 10 / WIDTH_6S_SCALE * 3 - 10 / WIDTH_6S_SCALE * 2) * 0.5);
            make.height.mas_equalTo(42 / HEIGHT_6S_SCALE);
        }];
        
        UIView *lineView3 = [[UIView alloc]init];
        lineView3.backgroundColor = getColor(@"B4B0C0");
        [_headerView addSubview:lineView3];
        [lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.top.equalTo(telephoneBtn.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(0.5);
        }];
        
        NSString *str = @"地址\n沈阳市和平区七经街八纬路79号附近";
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str];
        [attrStr addAttribute:NSFontAttributeName
                        value:DEF_FontSize_14
                        range:NSMakeRange(0, 2)];
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        //行间距
        paragraph.lineSpacing = 0;
        //段落间距
        paragraph.paragraphSpacing = 0;
        //对齐方式
        paragraph.alignment = NSTextAlignmentLeft;
        //指定段落开始的缩进像素
        paragraph.firstLineHeadIndent = 0;
        //调整全部文字的缩进像素
        paragraph.headIndent = 0;
//        attrStr添加段落设置
        [attrStr addAttribute:NSParagraphStyleAttributeName
                        value:paragraph
                        range:NSMakeRange(0, 2)];
        
        UILabel *label = [[UILabel alloc]init];
        label.backgroundColor = [UIColor clearColor];
        //自动换行
        label.numberOfLines = 0;
        //设置label的富文本
        label.attributedText = attrStr;
        self.label = label;
        //label高度自适应
        [label sizeToFit];
        [_headerView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.top.equalTo(lineView3.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(38.5 / HEIGHT_6S_SCALE);
        }];
        
        [_headerView addSubview:self.vadioImageView];
        [self.vadioImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(label.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(170 / HEIGHT_6S_SCALE);
        }];
        [_headerView addSubview:self.effectView];
        [self.effectView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(label.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(170 / HEIGHT_6S_SCALE);
        }];
        
        UIImageView *middleImg = [[UIImageView alloc]init];
        middleImg.backgroundColor = [UIColor clearColor];
        middleImg.userInteractionEnabled = YES;
        middleImg.image = [UIImage imageNamed:@"WX20180620-93012"];
        middleImg.contentMode = UIViewContentModeScaleAspectFit;
        self.middleImg = middleImg;
        [_headerView addSubview:middleImg];
        [middleImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(label.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(170 / HEIGHT_6S_SCALE);
        }];
        UITapGestureRecognizer * imagesViewTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imagesViewTap:)];
        [middleImg addGestureRecognizer:imagesViewTapGestureRecognizer];
        
        UIButton *makeSureBtn = [[UIButton alloc]init];
        [makeSureBtn setBackgroundColor:getColor(mainColor)];
        [makeSureBtn setTitleColor:getColor(whiteColor) forState:UIControlStateNormal];
        makeSureBtn.titleLabel.font = DEF_FontSize_14;
        [makeSureBtn setTitle:@"确认预约" forState:UIControlStateNormal];
        [makeSureBtn addTarget:self action:@selector(makeSureBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        self.makeSureBtn = makeSureBtn;
        [_headerView addSubview:makeSureBtn];
        [makeSureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(middleImg.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(40 / HEIGHT_6S_SCALE);
        }];
        makeSureBtn.layer.cornerRadius = 5;
        makeSureBtn.layer.masksToBounds = YES;
        
    }
    return _headerView;
}
- (void)imagesViewTap:(UITapGestureRecognizer *)tapgesture
{
    NSMutableArray *imageViewArray = [NSMutableArray array];
    [imageViewArray addObject:self.middleImg];

    NSMutableArray *imagesArray = [NSMutableArray array];
    [imagesArray addObject:self.detalMakeSureModel.slideimg];
//    if (self.imagesblock) {
//        self.imagesblock(imagesArray,0, imageViewArray);
//    }
    [self showImageWithPhotoURLsArray:imagesArray startIndex:0 fromViews:imageViewArray]; // 大图浏览
    
}
- (UIView *)footerView
{
    if (!_footerView) {
        _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.01)];
    }
    return _footerView;
}

#pragma mark implement BMKMapViewDelegate

/**
 *根据anntation生成对应的View
 *@param mapView 地图View
 *@param annotation 指定的标注
 *@return 生成的标注View
 */
- (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id <BMKAnnotation>)annotation
{
    // 生成重用标示identifier
    NSString *AnnotationViewID = @"xidanMark";
    
    // 检查是否有重用的缓存
    BMKAnnotationView* annotationView = [view dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
    
    // 缓存没有命中，自己构造一个，一般首次添加annotation代码会运行到此处
    if (annotationView == nil) {
        annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
        ((BMKPinAnnotationView*)annotationView).pinColor = BMKPinAnnotationColorRed;
        // 设置重天上掉下的效果(annotation)
        ((BMKPinAnnotationView*)annotationView).animatesDrop = YES;
    }
    
    // 设置位置
    annotationView.centerOffset = CGPointMake(0, -(annotationView.frame.size.height * 0.5));
    annotationView.annotation = annotation;
    // 单击弹出泡泡，弹出泡泡前提annotation必须实现title属性
    annotationView.canShowCallout = YES;
    // 设置是否可以拖拽
    annotationView.draggable = NO;
    
    return annotationView;
}
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
{
    [mapView bringSubviewToFront:view];
    [mapView setNeedsDisplay];
}
- (void)mapView:(BMKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    NSLog(@"didAddAnnotationViews");
}
//- (NSMutableArray *)testArray{
//    if (!_testArray) {
//        _testArray = @[@{@"pic":@[@"http://39.108.212.163/ly/Uploads/5b07a98cbd0b9.jpg",
//                                  @"http://39.108.212.163/ly/Uploads/5b07a98cbd353.jpg",
//                                  @"http://39.108.212.163/ly/Uploads/5b07a98cbd5ad.jpg",
//                                  @"http://39.108.212.163/ly/Uploads/5b07a98cbd7e1.jpg",
//                                  @"http://39.108.212.163/ly/Uploads/5b07a98cbda36.jpg",
//                                  @"http://39.108.212.163/ly/Uploads/5b07a98cbdc74.jpg"]},
//                       @{@"pic":@[
//                                  @"http://39.108.212.163/ly/Uploads/5b07a98cbd5ad.jpg",
//                                  @"http://39.108.212.163/ly/Uploads/5b07a98cbd7e1.jpg",
//                                  @"http://39.108.212.163/ly/Uploads/5b07a98cbda36.jpg",
//                                  @"http://39.108.212.163/ly/Uploads/5b07a98cbdc74.jpg"]},
//                       @{@"pic":@[
//                                 @"http://39.108.212.163/ly/Uploads/5b07a98cbda36.jpg",
//                                 @"http://39.108.212.163/ly/Uploads/5b07a98cbdc74.jpg"]},
//                       @{@"pic":@[
//                                 @"http://39.108.212.163/ly/Uploads/5b07a98cbdc74.jpg"]}
//                       ].mutableCopy;
//    }
//    return _testArray;
//}
- (void) showImageWithPhotoURLsArray:(NSArray<NSString*>*)photosURLsArray startIndex:(NSInteger)startIndex fromViews:(NSArray*)fromViews{
    [[BrowPhotoView alloc]initWithFrame:self.view.bounds array:photosURLsArray selectIndex:startIndex];
}
- (NSMutableArray *)datamuArray
{
    if (!_datamuArray) {
        _datamuArray = @[].mutableCopy;
    }
    return _datamuArray;
}
- (UIImageView *)vadioImageView
{
    if (!_vadioImageView)
    {
        _vadioImageView = [[UIImageView alloc]init];
        _vadioImageView.backgroundColor = [UIColor clearColor];
    }
    return _vadioImageView;
}
- (UIVisualEffectView *)effectView
{
    if (!_effectView)
    {
        _effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
        _effectView.alpha = 0.9f;
    }
    return _effectView;
}
@end
